<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
   //基本语法:能理解不
   let arr = [1,2,3];

   let result  = arr.reduce((prev,next)=>{
          return prev + next;
   },0);
   console.log(result);
 
     //第一执行：prev = 0  next = 1     返回结果 1
     //第二次:   prev = 1   next = 2    返回结果3
     //第三次:   prev = 3   next = 3    返回结果6  

     let arr1 = [{attrId:'10:20',name:'曹操'},{name:'刘备'},{name:'孙尚香'},{attrId:'30:40',name:'曹操'}];

    let result1  = arr1.reduce((prev,next)=>{
            if(next.attrId){
               let [a,b] = next.attrId.split(':')
               prev.push({a,b});
           }
           return prev;
     },[])
     console.log(result1)
     //第一次:  prev  []                next  = {attrId:'10:20',name:'曹操'}     结果 [{a:10,b:20}]
     //第二次： prev  [{a:10,b:20}]     next  =  {name:'刘备'}                    结果 [{a:10,b:20}] 
     //第三次： prev  [{a:10,b:20}]      next = {name:'孙尚香'}                    结果 [{a:10,b:20}]
     //第四次:  prev  [{a:10,b:20}]      next = {attrId:'10:20',name:'曹操'}      结果  [{a:10,b:20},{a:30,b:40}]
 

</script>